package xyz.scootaloo.oj.leetcode

import org.junit.Test
import xyz.scootaloo.common.TestDsl

/**
 * @author flutterdash@qq.com
 * @since 2021/7/3 8:23
 */
class P997 : TestDsl {

    private fun sortedSquares(nums: IntArray): IntArray {
        val res = IntArray(nums.size)
        var pos = nums.size - 1
        var right = pos
        var left = 0
        while (pos >= 0) {
            val leftValue = nums[left] * nums[left]
            val rightValue = nums[right] * nums[right]
            if (rightValue > leftValue) {
                res[pos] = rightValue
                right--
            } else {
                res[pos] = leftValue
                left++
            }
            pos--
        }

        return res
    }

    @Test
    fun test0() {
        val array1 = intArrayOf(-4, -1, 0, 3, 10)
        sortedSquares(array1).log()
        val array2 = intArrayOf(-7, -3, 2, 3, 11)
        sortedSquares(array2).log()
    }

}
